<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>javascript 阶段</title>
</head>
<body>


    <script>

        // 小数
        var num = 3.1414926;
        // 保留两位数 (四舍五入)
        console.log(num.toFixed(2));// 3.14
        console.log(num.toFixed(1));// 3.1
        console.log(num.toFixed(3));// 3.141


        var num1 = 3.1415890;
        console.log(num1.toFixed(4));
        console.log(num1.toFixed(1));
        console.log(num1.toFixed(3));
    </script>
</body>
</html>